#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Processes/ForwardMeasureProcess1D.h>
#pragma unmanaged 
#include <ql\processes\hullwhiteprocess.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Math;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Processes {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IHullWhiteForwardProcess
	public ref class CHullWhiteForwardProcess : 
            public CForwardMeasureProcess1D,
            public Cephei::QL::Processes::IHullWhiteForwardProcess
	{
	protected: 
		boost::shared_ptr<QuantLib::HullWhiteForwardProcess>* _ppHullWhiteForwardProcess;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::HullWhiteForwardProcess>* _phHullWhiteForwardProcess;
#endif
		Object^ _HullWhiteForwardProcessOwner;     // reference to object that manages the storage for this object
	internal:
		CHullWhiteForwardProcess (Cephei::QL::Termstructures::IYieldTermStructure^ h, Double a, Double sigma);
        CHullWhiteForwardProcess (boost::shared_ptr<QuantLib::HullWhiteForwardProcess>& childNative, Object^ owner);
        CHullWhiteForwardProcess (QuantLib::HullWhiteForwardProcess& childNative, Object^ owner);
        CHullWhiteForwardProcess (CHullWhiteForwardProcess^ copy);
        CHullWhiteForwardProcess (System::Type^ t);
#ifdef STRUCT
        CHullWhiteForwardProcess (QuantLib::HullWhiteForwardProcess childNative);
#endif       
#ifdef HANDLE
		CHullWhiteForwardProcess (QuantLib::Handle<QuantLib::HullWhiteForwardProcess>& childNative, Object^ owner);
		CHullWhiteForwardProcess (QuantLib::Handle<QuantLib::HullWhiteForwardProcess> childNative);
#endif
		virtual ~CHullWhiteForwardProcess ();
		!CHullWhiteForwardProcess ();

	internal:
		QuantLib::HullWhiteForwardProcess& GetReference ();
		boost::shared_ptr<QuantLib::HullWhiteForwardProcess>& GetShared ();
		QuantLib::HullWhiteForwardProcess* GetPointer ();
        void SetHullWhiteForwardProcess (boost::shared_ptr<QuantLib::HullWhiteForwardProcess> native)
        {
            if (_ppHullWhiteForwardProcess != NULL)
                delete _ppHullWhiteForwardProcess;
            _ppHullWhiteForwardProcess = new boost::shared_ptr<QuantLib::HullWhiteForwardProcess> (native);
            SetForwardMeasureProcess1D (boost::dynamic_pointer_cast<QuantLib::ForwardMeasureProcess1D> (*_ppHullWhiteForwardProcess));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::HullWhiteForwardProcess>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Double A 
        {
		    virtual Double get () ;
        }
		virtual Double Alpha (Double t) ;
		virtual Double B (Double t, Double T2) ;
		virtual Double Diffusion (Double t, Double x) ;
		virtual Double Drift (Double t, Double x) ;
		virtual Double Expectation (Double t0, Double x0, Double dt) ;
		virtual Double M_T (Double s, Double t, Double T2) ;
        property Double Sigma 
        {
		    virtual Double get () ;
        }
		virtual Double StdDeviation (Double t0, Double x0, Double dt) ;
		virtual Double Variance (Double t0, Double x0, Double dt) ;
        property Double X0 
        {
		    virtual Double get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CHullWhiteForwardProcess_Factory : public System::MarshalByRefObject,  public IHullWhiteForwardProcess_Factory
	{
	public:
        virtual IHullWhiteForwardProcess^ Create (Cephei::QL::Termstructures::IYieldTermStructure^ h, Double a, Double sigma);
    };
   
/*Cephei*/ } /*QL*/ } /*Processes */}
